<?php

/**
 * ErrorController.php
 *
 * Holds class ErrorController
 *
 * @package Application
 * @subpackage Controllers
 */

/**
 * ErrorController
 *
 * Error controller
 *
 * @package Application
 * @subpackage Controllers
 */
class ErrorController extends PageController {

	/**
	 * Displays 403 error page
	 *
	 * @return void
	 */
	public function action401() {
//		// Log
//		$forbiddenLog = new Log($this->getRequest(), APP . 'logs/status-403.txt');
//		$forbiddenLog->write('403 Forbidden');
//
//		// Configure page
//		$status = 403;//HTTP status code
//		$this->getResponse()->setStatus($status);
//		$this->set('title', $this->_appendTitle($this->getLanguage()->get('status')->get('code')->get($status)));
//
//		// Display content
//		$this->setTemplate('content', dirname(__FILE__) . '/../views/error/message.php')
//		->set('error',        $status . ' ' . $this->getLanguage()->get('status')->get('code')->get($status))
//		->set('errorMessage', $this->getLanguage()->get('status')->get('message'));

		$status = 401;
		$this->error = $this->getLanguage()->get('status')->get('code')->get($status);
		$this->errorMessage = $this->getLanguage()->get('status')->get('message');
		$this->customTitle = $this->getLanguage()->get('status')->get('code')->get($status);
	}

	/**
	 * Displays 404 error page
	 *
	 * @return void
	 */
	public function action404() {
		$status = 404;
		$this->error = $this->getLanguage()->get('status')->get('code')->get($status);
		$this->errorMessage = $this->getLanguage()->get('status')->get('message');
		$this->customTitle = $this->getLanguage()->get('status')->get('code')->get($status);
	}

	/**
	 * Displays 500 error page
	 *
	 * @return void
	 */
	public function action500() {

		// Get resources
		try {
			$exception = $this->getArgument('exception');
			if(!($exception instanceof Exception)) {
				throw new Exception('Exception parameter is not an instance of Exception');
			}
		}
		catch(Exception $e) {//invalid
			return $this->action404();
		}

//		// Handle exception
		if(DEVELOPMENT) {
			$this->exception = print_r($exception, true);
		}
//		else {//log
//			$errorLog = new Log($this->getRequest(), APP . 'logs/status-500.txt');
//			$errorLog->write($exception->getMessage(), $exception->getFile(), $exception->getLine());
//		}
//
//		// Configure page
//		$status = 500;//HTTP status code
//		$this->getResponse()->setStatus($status);
//		//		$this->set('title', $this->_appendTitle($this->getLanguage()->get('status')->get('code')->get($status)));
//
//		// Display content
//		$this->error = $status . ' ' . $this->getLanguage()->get('status')->get('code')->get($status);
		//		$this->errorMessage = $this->getLanguage()->get('status')->get('message');
		
		$status = 500;
		$this->error = $this->getLanguage()->get('status')->get('code')->get($status);
		$this->errorMessage = $this->getLanguage()->get('status')->get('message');
		$this->customTitle = $this->getLanguage()->get('status')->get('code')->get($status);
	}
}
